﻿Imports System.Data.OleDb

Public Class addBook
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not userLoggedIn() Then
            Response.Redirect("list.aspx?error=You%20must%20be%20logged%20in%20to%20add%20books")
        End If
    End Sub


    Function bt_Submit_Click(sender As Object, e As EventArgs) Handles bt_Submit.Click

  

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim authorId As Int32 = getAuthorID(tb_Author.Text)

        If authorId = -1 Then
            addNewAuthor(tb_Author.Text)
            authorId = getAuthorID(tb_Author.Text)
        End If

        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newfileName = myGUID.ToString() + ".jpg"

        If fu_photo.HasFile Then
            fu_photo.SaveAs(Request.MapPath("pictures") & "/" & newfileName)
        End If

        addNewBook(tb_ISBN.Text, tb_BookTitle.Text, tb_Description.Text, authorId, tb_YearPublished.Text, newfileName)
        Response.Redirect("list.aspx?added=" + tb_BookTitle.Text)

        Return "confirmationBookAdd.aspx"
    End Function

End Class